﻿using Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WsdShop.IService;
using WsdShop.Model.Enum;

namespace WeChat.Controllers
{
    public class ActivityController : BaseController
    {
        protected ISpikeService spikeservice;
        protected ICarouselService carouselservice;
        protected ISpecialTopicService topicservice;
        protected IActivityService activityservice;
        protected IActivityTeam activityteam;
        protected IActivityTeamMembersService activityteammembersservice;
        protected IActivityRuleService activityruleservice;

        public ActivityController(IMemberService s, ISpikeService _spikeservice, ICarouselService _carouselservice, ISpecialTopicService _topicservice, IActivityService _activityservice, IActivityTeam _activityteam, IActivityTeamMembersService _activityteammembersservice, IActivityRuleService _activityruleservice) : base(s)
        {
            spikeservice = _spikeservice;
            carouselservice = _carouselservice;
            topicservice = _topicservice;
            activityservice = _activityservice;
            activityteam = _activityteam;
            activityteammembersservice = _activityteammembersservice;
            activityruleservice = _activityruleservice;
        }

        public ActionResult MyActivity()
        {
            return View();
        }

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Role()
        {
            return View();
        }

        public ActionResult Role1()
        {
            return View();
        }

        [HttpPost]
        public ActionResult GetRole(int type)
        {
            return Json(new { Result = activityruleservice.GetActivityRuleAll(type) });
        }

        /// <summary>
        /// 限时抢购列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        // GET: Activity
        public ActionResult SpikeList()
        {
            return View();
        }

        /// <summary>
        /// 数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetSpikeList()
        {
            return Json(new { Result = spikeservice.GetSpikeList(), CarouselList = carouselservice.GetCarousel((int)CarouselTypeEnum.限时抢购) });
        }



        [HttpGet]
        public ActionResult SpecialTopic()
        {
            return View();
        }


        [HttpPost]
        public ActionResult SpecialTopicProduct(/*int Skip, int Take,*/ int Id)
        {
            //int total = 0;
            //var list = topicservice.SpecialTopicProduct(Skip, Take, Id, out total);
            //return Json(new { Total = total, Results = list });
            return Json(new { Result = topicservice.SpecialTopicEdit(Id)});
        }

        /// <summary>
        /// 获取第一个详情
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetActivityTop1()
        {
            return Json(new { Result = activityservice.GetActivityTop1() });
        }


        /// <summary>
        /// 获取所有的一分钱活动
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetActivityListAll()
        {
            return Json(new { Results = activityservice.GetActivityListAll() });
        }

        /// <summary>
        /// 一分钱活动详情页
        /// </summary>
        /// <returns></returns>
        public ActionResult ActivityInfo()
        {
            return View();
        }


        /// <summary>
        /// 获取一分钱活动详情
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetVActivityInfo(int id)
        {
            return Json(new { Result = activityservice.GetVActivityInfo(id) });
        }


        /// <summary>
        /// 一分钱活动团列表页
        /// </summary>
        /// <returns></returns>
        public ActionResult ActivityTeamList()
        {
            return View();
        }

        ///// <summary>
        ///// 根据活动id获取一分钱活动团
        ///// </summary>
        ///// <param name="Skip"></param>
        ///// <param name="Take"></param>
        ///// <param name="id"></param>
        ///// <returns></returns>
        //public ActionResult GetActivityTeamList(int Skip, int Take, int id)
        //{
        //    int total = 0;
        //    var list = activityteam.GetActivityTeamList(Skip, Take, id, ref total);
        //    return Json(new { Total = total, Results = list });
        //}



        /// <summary>
        /// 一分钱活动团详情页
        /// </summary>
        /// <returns></returns>
        public ActionResult ActivityTeamInfo()
        {
            return View();
        }

        /// <summary>
        /// 根据一分钱活动团id获取团信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetActivityTeamInfo(int id)
        {
            int total = 0;
            var model = activityteam.GetActivityTeamInfo(id, ref total);
            bool isJoin = false;
            var atm = activityteammembersservice.FindActivityTeamMembersInfo("UserId=" + CurrentLoginUser.Id + " and ActivityTeamId=" + id);
            if (atm != null)
            {
                isJoin = true;
            }

            return Json(new { Result = model, UserId = CurrentLoginUser.Id,IsJoin=isJoin });
        }


        public JsonResult GetPointCarouselList(int type)
        {
            Result result = new Result();
            try
            {

                result.data = carouselservice.GetCarousel(type);
                result.isSuccess = true;
            }
            catch (Exception ex)
            {

                result.msg = ex.Message;
            }

            return Json(result);
        }

        /// <summary>
        /// 我的一分钱活动页
        /// </summary>
        /// <returns></returns>
        public ActionResult MyActivityList()
        {
            return View();
        }


        /// <summary>
        /// 我的一分钱活动数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetMyActivityList(int Skip, int Take)
        {
            int total = 0;
            var list = activityteammembersservice.GetActivityTeamMembersList(Skip, Take, CurrentLoginUser.Id, ref total);
            return Json(new { Total = total, Results = list });
        }

    }
}